﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MH.Lib.Data;

namespace MH.Lib.Actions
{
    public class FindReplaceAction
        : IAction
    {
        public FindReplaceAction(string from, string to)
        {
            m_from = from;
            m_to = to;
        }


        #region IAction

        /// <summary>
        /// Attempts to apply this action to given person
        /// </summary>
        /// <param name="person"> Target person </param>
        /// <returns> True if successful, false otherwise </returns>
        public bool Apply(IPerson person)
        {
            try
            {
                string temp = person.FirstName.Replace(m_from, m_to);
                person.FirstName = temp;

                temp = person.LastName.Replace(m_from, m_to);
                person.LastName = temp;

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        #endregion // IAction


        #region Private

        private string m_from;
        private string m_to;

        #endregion // Private
    }
}
